<template>
  <div id="app">
    <!-- 顶部标题 -->
    <header>
      <span class="goBack" v-show="isShowBack" @click="goBack">
        <van-icon name="arrow-left" />返回
      </span>
      疯狂 div 组
      <span class="addProd" v-show="isShowaddProd" @click="addProd">添加</span>
    </header>

    <!-- 中间内容 -->
    <div class="content">
      <!-- 添加路由占位符 -->
      <router-view></router-view>
    </div>

    <!-- 底部bar -->
    <van-tabbar v-model="active" route>
      <van-tabbar-item icon="home-o" to="/home">首页</van-tabbar-item>
      <van-tabbar-item icon="search" to="/search">搜索</van-tabbar-item>
      <van-tabbar-item icon="shopping-cart-o" :info="totalNum" to="/shopcar">购物车</van-tabbar-item>
      <!-- 自定义引用外部图标 -->
      <van-tabbar-item to="/member">
        <span>会员</span>
        <i class="iconfont icon-icon_zhanghao" slot="icon"></i>
      </van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  data() {
    return {
      active: 0
    };
  },
  computed: {
    ...mapState(['totalNum']),
    isShowBack() {
      return this.$route.path === "/home" ? false : true;
    },
    isShowaddProd() {
      return this.$route.path === "/search" ? true : false;
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    addProd() {
      this.$router.push('/goods/add');
    }
  }
};
</script>

<style lang="less" scoped>
html, body {
  width: 100%;
}
header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: #fff;
  font-size: 14px;
  background-color: #1989fa;
  z-index: 9;

  span {
    display: flex;
    align-items: center;
  }

  .goBack {
    position: absolute;
    top: 0;
    left: 10px;
    .van-icon {
      margin-right: 3px;
    }
  }
  
  .addProd {
    position: absolute;
    top: 0;
    right: 10px;
  }
}
.content {
  margin-top: 40px;
  padding-bottom: 50px;
}
</style>
